package toubiao.domain.po.manage;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

@Entity
@Table(name = "role")
@DynamicInsert(true)
@DynamicUpdate(true)
public class PoRole implements java.io.Serializable {

	private int id;
	private PoRole trole;
	private String name;
	private String remark;
	private Integer seq;
	private Set<PoRole> roleSet = new HashSet<PoRole>(0);
	private Set<PoResource> tresourceSet= new HashSet<PoResource>(0);
	private Set<PoUser> userSet = new HashSet<PoUser>(0);

	public PoRole() {
	}

	public PoRole(int id, String name) {
		this.id = id;
		this.name = name;
	}

	public PoRole(int id, PoRole trole, String name, String remark, Integer seq, Set<PoRole> troles, Set<PoResource> tresources, Set<PoUser> tusers) {
		this.id = id;
		this.trole = trole;
		this.name = name;
		this.remark = remark;
		this.seq = seq;
		this.roleSet = troles;
		this.tresourceSet = tresources;
		this.userSet = tusers;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "PID")
	public PoRole getTrole() {
		return this.trole;
	}

	public void setTrole(PoRole trole) {
		this.trole = trole;
	}

	@Column(name = "NAME", nullable = false, length = 100)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "REMARK", length = 200)
	public String getRemark() {
		return this.remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Column(name = "SEQ")
	public Integer getSeq() {
		return this.seq;
	}

	public void setSeq(Integer seq) {
		this.seq = seq;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "trole")
	public Set<PoRole> getRoleSet() {
		return this.roleSet;
	}

	public void setRoleSet(Set<PoRole> roleSet) {
		this.roleSet = roleSet;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "role_resource", joinColumns = { @JoinColumn(name = "ROLE_ID", nullable = false, updatable = true) }, inverseJoinColumns = { @JoinColumn(name = "RESOURCE_ID", nullable = false, updatable = true) })
	@Cascade({ CascadeType.ALL })
	public Set<PoResource> getTresourceSet() {
		return this.tresourceSet;
	}

	public void setTresourceSet(Set<PoResource> tresources) {
		this.tresourceSet = tresources;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "user_role", joinColumns = { @JoinColumn(name = "ROLE_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "USER_ID", nullable = false, updatable = false) })
	public Set<PoUser> getUserSet() {
		return this.userSet;
	}

	public void setUserSet(Set<PoUser> userSet) {
		this.userSet = userSet;
	}

}
